package ig.metrica.ui.modelo;

import bsh.util.JConsole;
import ig.util.LoadProperties;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ig.metrica.ui.PantallaSevinproPanel;
import java.awt.*;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class PantallaDatosBasicosModelo extends PantallaSevinproPanel {
    
    private JTextField txtNombre;
    private javax.swing.JProgressBar Progreso;    
    private Integer idModelo = null;
    private JComboBox comboFactor=null;
    private JComboBox comboFactor1=null;
    private JPanel panelSuperior=null;
    private JPanel panelCentral=null;
    private JTextArea textDescripcion=null;
    private JComboBox[] comboBoxsColumns=new JComboBox[1];
    public WizzardModelo wizzardModelo=null;
    

    @Override
    public JComboBox[] getComboBoxsColumnsTable1() {
        return comboBoxsColumns;
    }

    private JComboBox[] comboBoxsColumnsTable2=new JComboBox[1];
    public JComboBox[] getComboBoxsColumnsTable2() {
        return comboBoxsColumnsTable2;
    }

    public void apendDescription(String msg){
        textDescripcion.append(msg);
        textDescripcion.setCaretPosition(textDescripcion.getDocument().getLength());
        textDescripcion.setVisible(true);
    }
    public PantallaDatosBasicosModelo(WizzardModelo wizzardModelo){
        this.threadModelos=wizzardModelo.dialogo;
        this.wizzardModelo=wizzardModelo;
        init();
        setLayout( new BorderLayout() );
        add( panelSuperior = new JPanel(), BorderLayout.NORTH );
        add( panelCentral = new JPanel(), BorderLayout.CENTER );

        panelCentral.setLayout( new BorderLayout());
        /*panelCentral.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createEmptyBorder(8, 0, 0, 0), BorderFactory.createEtchedBorder()));*/

        panelCentral.add(new JScrollPane(textDescripcion = new JTextArea()));
        //textDescripcion.setBackground(new Color(212,208,200));
        textDescripcion.setEditable(false);
        textDescripcion.setVisible(false);
        //textDescripcion.setFont(new java.awt.Font(Font.MONOSPACED, 0, 11));
//        add( resumen=new PResumen(),BorderLayout.CENTER);
        panelSuperior.setLayout( new FlowLayout( FlowLayout.CENTER));
        panelSuperior.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createEmptyBorder(8, 0, 0, 0), BorderFactory.createEtchedBorder()));

        //--------------------
        panelSuperior.add( new JLabel("Nombre") );
        panelSuperior.add( txtNombre = new JTextField(30) );
        //txtNombre.setSize(500, txtNombre.getHeight());
        //txtNombre.setPreferredSize(new Dimension(200, 28 ));
        
        panelSuperior.add( new JLabel("Riesgo") );
        comboFactor = new JComboBox();
        comboFactor.addItem("Liquidez");
        comboFactor.addItem("Mercado");
        comboFactor.addItem("Liquidez & Mercado");
        panelSuperior.add(comboFactor);
        
        panelSuperior.add( new JLabel("Tipo") );
        comboFactor1 = new JComboBox();
        Properties prop=LoadProperties.loadPropertiess("server/tmodelos/modelos.properties");
        int i=1;
        while(prop.getProperty("label"+i)!=null){
            comboFactor1.addItem(prop.getProperty("label"+i));
            i++;
        }
        panelSuperior.add(comboFactor1);
        add(Progreso,BorderLayout.SOUTH);
    }
    private void init(){
        Progreso = new javax.swing.JProgressBar();
        Progreso.setFont(new java.awt.Font("Dialog", 0, 10));
        Progreso.setStringPainted(true);
    }
    
    public void setProgreso(int value,String mensaje){
        this.Progreso.setValue(value);
        this.Progreso.setString(mensaje);
        //this.apendDescription(mensaje);
    }
    
    public String getNombreModelo(){
        return txtNombre.getText().trim();
    }
    
    /**
     * 0 Riesgo de liquidez
     * 1 Riesgo de mercado
     * 2 Riesgo de Liquides y mercado
     */
    public Integer getTipoRiesgo(){
        return this.comboFactor.getSelectedIndex();
    }
    
    public Integer getTipoModelo(){
        return this.comboFactor1.getSelectedIndex();
    }
    
    public void setDatos(String _nombre,Integer tipoRiesgo,Integer tipoModelo){
        this.txtNombre.setText( _nombre );
        this.comboFactor.setSelectedIndex(tipoRiesgo);
        this.comboFactor1.setSelectedIndex(tipoModelo);
    }
    
    public void setData(Hashtable<String, Object> h){
        this.setIdModelo( (Integer) h.get("id") );
        this.txtNombre.setText( h.get("nombre")+"" );
        this.comboFactor.setSelectedIndex( (Integer) h.get("tipoRiesgo") );
        this.comboFactor1.setSelectedIndex( (Integer) h.get("tipoModelo") );        
    }
    
    public Hashtable<String, Object> getData(){
        Hashtable<String, Object> h = new Hashtable<String, Object>();
        h.put("id", this.getIdModelo() );
        h.put("nombre", this.txtNombre.getText() );
        h.put("tipoRiesgo", this.comboFactor.getSelectedIndex() );
        h.put("tipoModelo", this.comboFactor1.getSelectedIndex()  );
        return h;
    }
    
    
    public String getTitulo(){
        return "Datos Basicos del Modelo";
    }
    
    public void setModificable(boolean b) {
        this.txtNombre.setEditable(b);
        this.comboFactor.setEnabled(b);
        this.comboFactor1.setEnabled(b);
    }
    
    public void limpiarCampos(){
        txtNombre.setText("");
    }
    
    public void salir() throws Exception {
    }
    
    public Integer getIdModelo() {
        return idModelo;
    }
    
    public void setIdModelo(Integer i) {
        this.idModelo=i;
    }
    
    void setVisisbleProgreso(boolean b) {
        this.Progreso.setVisible(false);
        this.Progreso.setValue(0);
        panelSuperior.setLayout( new FlowLayout( FlowLayout.CENTER));
        this.repaint();
        this.updateUI();
    }
    
    boolean isProcesando() {
        return this.Progreso.isVisible();
    }

    public javax.swing.table.AbstractTableModel getClonModelTable_1() throws CloneNotSupportedException{
        return null;
    }

    public javax.swing.table.AbstractTableModel getClonModelTable_2() throws CloneNotSupportedException{
        return null;
    }

    public javax.swing.table.AbstractTableModel getClonModelTable_3() throws CloneNotSupportedException{
        return null;
    }

    @Override
    protected void eliminarLlaveEnTodasLasTablas(java.util.List<Object> keys) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
